{include file="public/header" /}
<style>
    .layui-form-item{
        margin-bottom: 5px
    }
    .layui-form-label{
        width: 172px;
    }
    .layui-input-block{
        margin-left: 180px
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>提成</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md12" style="width: 100%">
                            <label class="layui-form-label" style="color: red;width: 12%">实际总金额：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="totalPrice" id="totalPrice" value="{$serve.serve_total_price}" class="layui-input" style="width: 60%;" disabled>
                            </div>

                            <label class="layui-form-label" style="color: red;width: 10%">提成金额：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="tcPrice" id="tcPrice" value="{$td}" class="layui-input" style="width: 60%;" disabled>
                            </div>

                            <label class="layui-form-label" style="color: red;width: 13%">评价星级系数：</label>
                            <div class="layui-input-inline">
                                <input type="text" id="startRatio" value="{$serve.serve_star_ratio}" class="layui-input" style="width: 60%;" disabled>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md12">
                            <label class="layui-form-label">产品销售额提成：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="real_produce_price" id="pPrice" oninput="countPrice(0, this.value, this.id)" value="{$serve.serve_produce_price}" placeholder="产品销售额" class="layui-input" >
                            </div>

                            <label class="layui-form-label">比例（%）：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="produce_ratio" id="pRatio" oninput="countPrice(1, this.value, this.id)" value="{$product_ratio}" placeholder="提成比例" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md12">
                            <label class="layui-form-label">技术销售额提成：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="real_jishu_price" id="jPrice" oninput="countPrice(2, this.value, this.id)" value="{$serve.serve_jishu_price}" placeholder="技术销售额" class="layui-input">
                            </div>

                            <label class="layui-form-label">比例（%）：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="jishu_ratio" id="jRatio" oninput="countPrice(3, this.value, this.id)" value="{$jishu_ratio}" placeholder="提成比例" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md12">
                            <label class="layui-form-label">套餐销售额提成：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="real_taoc_price" id="tPrice" oninput="countPrice(4, this.value, this.id)" value="{$serve.serve_taoc_price}" placeholder="套餐销售额" class="layui-input">
                            </div>

                            <label class="layui-form-label">比例（%）：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="taoc_ratio" id="tRatio" oninput="countPrice(5, this.value, this.id)" value="{$taoc_ratio}" placeholder="提成比例" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md12">
                            <label class="layui-form-label">其它销售额提成：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="real_other_price" id="oPrice" oninput="countPrice(6, this.value, this.id)" value="{$serve.serve_other_price}" placeholder="其它销售额" class="layui-input">
                            </div>

                            <label class="layui-form-label">比例（%）：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="other_ratio" id="oRatio" oninput="countPrice(7, this.value, this.id)" value="{$other_ratio}" placeholder="提成比例" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">其它品牌销售额：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="real_notc_price" id="nPrice" oninput="countPrice(8, this.value, this.id)" value="{$serve.serve_notc_price}" placeholder="其它品牌销售额，没有请填0" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">备注：</label>
                            <div class="layui-input-block">
                                <textarea name="serve_remark" class="layui-textarea" lay-verify="required" placeholder="备注"></textarea>
                            </div>
                        </div>

                        <input type="hidden" value="{$serve_id}" name="serve_id">
                        <input type="hidden" value="{$serve.serve_star_ratio}" id="star_ratio">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">确认
                                </button>
                                <!--<button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}

<script>
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('tc')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        });
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });

    });
</script>
<script>
    var pPrice = $('#pPrice').val(); // 产品销售额
    var pRatio = $('#pRatio').val(); // 产品销售额提成比例
    var jPrice = $('#jPrice').val(); // 技术销售额
    var jRatio = $('#jRatio').val(); // 技术销售额提成比例
    var tPrice = $('#tPrice').val(); // 套餐销售额
    var tRatio = $('#tRatio').val(); // 套餐销售额提成比例
    var oPrice = $('#oPrice').val(); // 其它销售额
    var oRatio = $('#oRatio').val(); // 其它销售额提成比例
    var nPrice = $('#nPrice').val(); // 其它品牌销售额
    var p = [pPrice, pRatio, jPrice, jRatio, tPrice, tRatio, oPrice, oRatio, nPrice];
    function countPrice(type, value, id){
        var _val = value.replace(/[^\d.]/g,''); // 对象值
        $('#' + id).val(_val);
        p[type] = _val ? _val : 0;
        jisuan();
    }

    function jisuan(){
        var totalPrice = p[0] * 1 + p[2] * 1 + p[4] * 1 + p[6] * 1 + p[8] * 1;
        var star_ratio = $('#star_ratio').val();
        var td = (p[0] * p[1] * 100 + p[2] * p[3] * 100 + p[4] * p[5] * 100 + p[6] * p[7] * 100) * star_ratio / 10000;
        $('#totalPrice').val(totalPrice);
        $('#tcPrice').val(td);
    }
</script>
</body>
</html>
